package com.atlzk.seckill.seckill.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.atlzk.group.tgou.entity.ResultMsg;
import com.atlzk.seckill.seckill.service.PorderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.atlzk.seckill.seckill.entity.SorderEntity;
import com.atlzk.seckill.seckill.service.SorderService;
import com.atlzk.common.utils.PageUtils;
import com.atlzk.common.utils.R;



/**
 * 
 *
 * @author liuzekun
 * @email 2803587841@gmail.com
 * @date 2021-06-30 16:41:32
 */
@RestController
@RequestMapping("seckill/sorder")
public class SorderController {



    @Autowired
    private SorderService sorderService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("seckill:sorder:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sorderService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("seckill:sorder:info")
    public R info(@PathVariable("id") Long id){
		SorderEntity sorder = sorderService.getById(id);

        return R.ok().put("sorder", sorder);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("seckill:sorder:save")
    public R save(@RequestBody SorderEntity sorder){
		sorderService.save(sorder);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("seckill:sorder:update")
    public R update(@RequestBody SorderEntity sorder){
		sorderService.updateById(sorder);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("seckill:sorder:delete")
    public R delete(@RequestBody Long[] ids){
		sorderService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @RequestMapping("/seckill/{userId}/{seckillId}")
    public R seckill(@PathVariable("userId") Long userId,@PathVariable("seckillId") Long seckillId) {
        ResultMsg resultMsg = sorderService.seckill(userId, seckillId);
        return R.ok().put("ResultMsg", resultMsg);
    }

}
